function iEndingTime = ComputeEndingTime( atOccupancyEvents, iStartingTime )
	%
	bWeSawAtLeastOneValidEvent = false;
	%
	for iEvent = 1:numel( atOccupancyEvents )
		%
		if( atOccupancyEvents(iEvent).bIsValid )
			%
			bWeSawAtLeastOneValidEvent = true;
			iEndingTimeOfLastValidEvent = atOccupancyEvents(iEvent).aafRawData(end, 2);
			%
		end;%
		%
	end;% cycle on the events
	%
	if( bWeSawAtLeastOneValidEvent )
		%
		iEndingTime = iEndingTimeOfLastValidEvent + 1;
		%
	else%
		%
		iEndingTime = iStartingTime;
		%
	end;%
	%
end % function
